/**********************************************************************
* Filename: Bilhete.java
* Created: 2013/05/30
* @author Fernando Brito e Abreu
**********************************************************************/
package org.quasar.airNova.businessLayer;

import org.quasar.airNova.persistenceLayer.Database;

import java.util.Set;

public class Bilhete
{
	
	/***********************************************************
	* @return all instances of class Bilhete
	***********************************************************/
	public static Set<Bilhete> allInstances()
	{
		return Database.allInstances(Bilhete.class);
	}
	
	private Reserva reserva;
	private Classe classe;
	private Realizacao realizacao;
	private int lugar;
	private String primeiro_nome;
	private String ultimo_nome;
	
	/**********************************************************************
	* Default constructor
	**********************************************************************/
	public Bilhete()
	{
	}
	
	/**********************************************************************
	* Parameterized constructor
	* @param reserva the reserva to initialize
	* @param classe the classe to initialize
	* @param realizacao the realizacao to initialize
	* @param lugar the lugar to initialize
	* @param primeiro_nome the primeiro_nome to initialize
	* @param ultimo_nome the ultimo_nome to initialize
	**********************************************************************/
	public Bilhete(Reserva reserva, Classe classe, Realizacao realizacao, int lugar, String primeiro_nome, String ultimo_nome)
	{
		this.reserva = reserva;
		this.classe = classe;
		this.realizacao = realizacao;
		this.lugar = lugar;
		this.primeiro_nome = primeiro_nome;
		this.ultimo_nome = ultimo_nome;
	}
	
	/**********************************************************************
	* ONE2MANY getter for Bilhete[*] <-> Reserva[1]
	* @return the reserva of the bilhete
	**********************************************************************/
	public Reserva reserva()
	{
		return reserva;
	}
	
	/**********************************************************************
	* ONE2MANY setter for Bilhete[*] <-> Reserva[1]
	* @param reserva the reserva to set
	**********************************************************************/
	public void setReserva(Reserva reserva)
	{
		this.reserva = reserva;
	}
	
	/**********************************************************************
	* ONE2MANY getter for Bilhete[*] <-> Classe[1]
	* @return the classe of the bilhete
	**********************************************************************/
	public Classe classe()
	{
		return classe;
	}
	
	/**********************************************************************
	* ONE2MANY setter for Bilhete[*] <-> Classe[1]
	* @param classe the classe to set
	**********************************************************************/
	public void setClasse(Classe classe)
	{
		this.classe = classe;
	}
	
	/**********************************************************************
	* ONE2MANY getter for Bilhete[*] <-> Realizacao[1]
	* @return the realizacao of the bilhete
	**********************************************************************/
	public Realizacao realizacao()
	{
		return realizacao;
	}
	
	/**********************************************************************
	* ONE2MANY setter for Bilhete[*] <-> Realizacao[1]
	* @param realizacao the realizacao to set
	**********************************************************************/
	public void setRealizacao(Realizacao realizacao)
	{
		this.realizacao = realizacao;
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the lugar of the bilhete
	**********************************************************************/
	public int lugar()
	{
		return lugar;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param lugar the lugar to set
	**********************************************************************/
	public void setLugar(int lugar)
	{
		this.lugar = lugar;
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the primeiro_nome of the bilhete
	**********************************************************************/
	public String primeiro_nome()
	{
		return primeiro_nome;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param primeiro_nome the primeiro_nome to set
	**********************************************************************/
	public void setPrimeiro_nome(String primeiro_nome)
	{
		this.primeiro_nome = primeiro_nome;
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the ultimo_nome of the bilhete
	**********************************************************************/
	public String ultimo_nome()
	{
		return ultimo_nome;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param ultimo_nome the ultimo_nome to set
	**********************************************************************/
	public void setUltimo_nome(String ultimo_nome)
	{
		this.ultimo_nome = ultimo_nome;
	}
	
	/**********************************************************************
	* User-defined operation specified in SOIL/OCL
	**********************************************************************/
	public Aeroporto Destino()
	{
		//	TODO
		//	return self.realizacao.realiza_se.chegada
		return null;
	}
	
	/**********************************************************************
	* User-defined operation specified in SOIL/OCL
	**********************************************************************/
	public Aeroporto Origem()
	{
		//	TODO
		//	return self.realizacao.realiza_se.partida
		return null;
	}
	
	/**********************************************************************
	* Object serializer
	**********************************************************************/
	public String toString()
	{
		return "Bilhete [reserva=" + reserva + ", classe=" + classe + ", realizacao=" + realizacao + ", lugar=" + lugar + ", primeiro_nome=" + primeiro_nome + ", ultimo_nome=" + ultimo_nome + "]";
	}
	
	//	-------------------------------------------------------------------------------
	//	INVARIANTS (TODO)
	/*
	inv bilhetesCompradosNoIntervaloDaCapacidadeDaClasse
		self.realizacao.aviao.classe->collectNested($e : Classe | $e.capacidade)->flatten->forAll(c1 : Capacidade | c1.classe.bilhetes->forAll(b1 : Bilhete | ((b1.lugar >= c1.primeiro_numero) and (b1.lugar <= c1.ultimo_numero))))
	
	inv umBilheteTemQueTerUmNumeroDeReservaDefinido
		self.reserva.n_reserva.isDefined
	
	inv bilheteCompradoParaUmaDeterminadaClasseEsseAviaoTemDePossuirEssaClasse
		self.realizacao.aviao.classe->includes(self.classe)
	
	*/
}
